{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "random-number-generator-tutorial.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/towardsai/tutorials/blob/master/random-number-generator/random_number_generator_tutorial.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "naANqJjn8wD1"
      },
      "source": [
        "# Random Number Generator Tutorial with Python\r\n",
        "\r\n",
        "* Tutorial: https://towardsai.net/p/data-science/random-number-generator-tutorial-with-python-3b35986132c7\r\n",
        "\r\n",
        "* Github: https://github.com/towardsai/tutorials/tree/master/random-number-generator"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZEPAjtjS8-71"
      },
      "source": [
        "## Generating pseudorandom numbers with Python's standard library\r\n",
        "\r\n",
        "Python has a built-in module called random to generate a variety of pseudorandom numbers. Although it is recommended that this module should not be used for security purposes like cryptographic uses this will do for machine learning and data science. This module uses a PRNG called Mersenne Twister."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Fuxpe_d79JCe"
      },
      "source": [
        "### Importing module: random"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "v_XtrcTHbVLw"
      },
      "source": [
        "import random"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "x-ocR9mht0Nl"
      },
      "source": [
        "### Random numbers within a range"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Jro9cAZydTQx",
        "outputId": "b62378d7-26a3-47e5-bb2c-99cfb290fcf9"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#generating random number between 10 and 20(both excluded)\r\n",
        "print(random.randrange(10, 20))\r\n",
        "\r\n",
        "#generating random number between 10 and 20(both included)\r\n",
        "print(random.randint(10, 20))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "16\n",
            "10\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aiL805zcuI5x"
      },
      "source": [
        "### Random element from a sequence"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "Sx6Y_kkNeh15",
        "outputId": "118db6df-6cdd-4209-daf9-610c150c84e1"
      },
      "source": [
        "#initialize the seed to 2\r\n",
        "random.seed(2)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing an element from the sequence\r\n",
        "random.choice(myseq)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'Towards'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rYmk9MNCumsG"
      },
      "source": [
        "### Multiple random selections with different possibilities"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "4092OaXthwnF",
        "outputId": "9ad68d15-2354-4636-9607-0c6637e866b0"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#random selection of length 15\r\n",
        "#10 time higher possibility of selecting 'Towards'\r\n",
        "#5 time higher possibility of selecting 'AI'\r\n",
        "#2 time higher possibility of selecting 'is'\r\n",
        "#2 time higher possibility of selecting 1\r\n",
        "random.choices(myseq, weights=[10, 5, 2, 2], k = 15)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Towards',\n",
              " 1,\n",
              " 'is',\n",
              " 'Towards',\n",
              " 'is',\n",
              " 'AI',\n",
              " 'Towards',\n",
              " 1,\n",
              " 'Towards',\n",
              " 'Towards',\n",
              " 'Towards',\n",
              " 'AI',\n",
              " 'Towards',\n",
              " 'AI',\n",
              " 'is']"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8bzlenjOyPDQ"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OV8qVvBhq8F6"
      },
      "source": [
        "### Random element from a sequence without replacement"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uusp2UGnq-HZ",
        "outputId": "23628c29-8e37-4cde-f6d4-8cd3a868d347"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing an element from the sequence\r\n",
        "random.sample(myseq, 2)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[1, 'Towards']"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WEnN82S7uGnr"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing an element from the sequence\r\n",
        "#you are trying to choose 5 random elements from a sequence of lenth 4\r\n",
        "#since the selection is without replacement it is not possible and hence the error\r\n",
        "random.sample(myseq, 35)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jTvuhB-Uu4CT"
      },
      "source": [
        "### Rearrange the sequence"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "PBcJ8c6Aj-5_",
        "outputId": "80cdb454-e157-4eca-cfa1-3ce053877de7"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#rearranging the order of elements of the list\r\n",
        "random.shuffle(myseq)\r\n",
        "myseq"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['AI', 'is', 'Towards', 1]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BzYw8LWJvE6Q"
      },
      "source": [
        "### Floating-point random number"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "NaygYVbRowvM",
        "outputId": "8ceacb9a-a373-485b-e629-2e648eeb4fdd"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#random float number between 0 and 1 \r\n",
        "random.random()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.376962302390386"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MozWVFNWvR5y"
      },
      "source": [
        "### Real-valued distributions"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "CICbelocpeim",
        "outputId": "be38ee28-c2c9-4af7-be6d-79a587bb04fc"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#random float number between 10 and 20 (both included)\r\n",
        "print(random.uniform(10, 20))\r\n",
        "\r\n",
        "#random float number mean 10 standard deviation 4\r\n",
        "print(random.gauss(10, 4))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "13.76962302390386\n",
            "16.90247841037158\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "vTyuEVdLhBr6"
      },
      "source": [
        "## Generating pseudorandom numbers with Numpy"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nCEvRzwLsmYl"
      },
      "source": [
        "#importing random module from numpy\r\n",
        "import numpy as np"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "k9pesYZurQD0"
      },
      "source": [
        "### Uniform distributed floating values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "S-d70kuOhFCr",
        "outputId": "96ebcde9-249a-4e0c-9214-4ac5326dfdbd"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#single uniformly distributed random number\r\n",
        "np.random.rand()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.8701241366272119"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "1VJ3YQvml1tm",
        "outputId": "cf2a7388-65cc-487b-e01a-1d6616928c9a"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#uniformly distributed random numbers of length 10: 1-D array\r\n",
        "np.random.rand(10)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([0.87012414, 0.58227693, 0.27883894, 0.18591123, 0.41110013,\n",
              "       0.11737555, 0.68496874, 0.43761106, 0.55622933, 0.36708032])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "yPzSEP93nEuL",
        "outputId": "e8aed558-d432-4953-f8d3-222445351194"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#uniformly distributed random numbers of 2 rows and 3 columns: 2-D array\r\n",
        "np.random.rand(2, 3)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0.87012414, 0.58227693, 0.27883894],\n",
              "       [0.18591123, 0.41110013, 0.11737555]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "q6pR3S5nrYTT"
      },
      "source": [
        "### Normal distributed floating values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "W_RfRgjcpC-S",
        "outputId": "0ff107d8-dbc1-44ca-cafe-c27eabe40b79"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#single normally distributed random number\r\n",
        "np.random.randn()"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0.22827308966608442"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "wct1BQrwhN3X",
        "outputId": "c0dd3f02-5556-45b8-a31f-8761f78f2038"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#normally distributed random numbers of length 10: 1-D array\r\n",
        "np.random.randn(10)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 0.22827309,  1.0268903 , -0.83958485, -0.59118152, -0.9568883 ,\n",
              "       -0.22232569, -0.61991511,  1.83790458, -2.05323076,  0.86858305])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "iumrAseopF_C",
        "outputId": "e2c8c3ec-9232-440f-a906-7e409b807101"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#normally distributed random numbers of 2 rows and 3 columns: 2-D array\r\n",
        "np.random.randn(2, 3)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[ 0.22827309,  1.0268903 , -0.83958485],\n",
              "       [-0.59118152, -0.9568883 , -0.22232569]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "stgI0z-oszqh"
      },
      "source": [
        ""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wIt3vyh5syUh"
      },
      "source": [
        "###  Uniformly distributed integers in a given range"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ooqNmqOKhqMU",
        "outputId": "d3c0a9e1-ff97-4fee-ce6c-60e19f826987"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#single uniformly distributed random integer between 10 and 20\r\n",
        "np.random.randint(10, 20)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "96f2VbvpiAyl",
        "outputId": "f03a4a1c-a445-497d-81cf-a0038d1b0135"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#uniformly distributed random integer between 0 to 100 of length 10: 1-D array\r\n",
        "np.random.randint(100, size=(10))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 4, 62, 90, 15, 61, 23, 44, 50,  8, 28])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "YeZz0M-ljiCb",
        "outputId": "00f0d405-6032-4268-bdd9-c4c2d2b303ad"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#uniformly distributed random integer between 0 to 100 of 2 rows and 3 columns: 2-D array\r\n",
        "np.random.randint(100, size=(2, 3))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[ 4, 62, 90],\n",
              "       [15, 61, 23]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7HkS96a6z1VT"
      },
      "source": [
        "### Random elements from a defined list"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "WFqxZWH1j5Gx",
        "outputId": "6f7b32b9-a369-41f5-a1d8-034d3fdd5631"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing an element from the sequence\r\n",
        "np.random.choice(myseq)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            },
            "text/plain": [
              "'Towards'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "FgTh5Rjux2dc",
        "outputId": "a19845be-de22-4cd0-8c59-4be2a81324b9"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing elements from the sequence: 2-D array\r\n",
        "np.random.choice(myseq, size=(2, 3))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([['is', 'AI', 'Towards'],\n",
              "       ['Towards', 'Towards', 'AI']], dtype='<U7')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Pigipq101CE_",
        "outputId": "40750a0d-9033-4f3e-825f-0a49b6438f2a"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "random.seed(25)\r\n",
        "\r\n",
        "#setting up the sequence\r\n",
        "myseq = ['Towards', 'AI', 'is', 1]\r\n",
        "\r\n",
        "#randomly choosing elements from the sequence with defined probabilities\r\n",
        "#The probability for the value to be 'Towards' is set to be 0.1\r\n",
        "#The probability for the value to be 'AI' is set to be 0.6\r\n",
        "#The probability for the value to be 'is' is set to be 0.05\r\n",
        "#The probability for the value to be 1 is set to be 0.25\r\n",
        "#0.1 + 0.6 + 0.05 + 0.25 = 1\r\n",
        "np.random.choice(myseq, p=[0.1, 0.6, 0.05, 0.25], size=(2, 3))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([['AI', 'AI', '1'],\n",
              "       ['1', 'Towards', 'AI']], dtype='<U7')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZS4isIDnAP2k"
      },
      "source": [
        "### Binomial distributed values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "XX10NN4e5jQq",
        "outputId": "6ea52129-5ae0-4e81-b336-d998bc29fba2"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#10 number of trials with probability of 0.5 each\r\n",
        "np.random.binomial(n=10, p=0.5, size=10)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([7, 5, 4, 4, 5, 3, 6, 5, 5, 4])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "rJwcPBGcB-0o"
      },
      "source": [
        "### Poisson Distribution values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "_MCNeA8SAWb8",
        "outputId": "55ccfcb7-e86c-411b-e17a-07a23a57bd5b"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#rate 2 and size 10\r\n",
        "np.random.poisson(lam=2, size=10)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([3, 1, 3, 1, 2, 2, 3, 3, 0, 2])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JP8CZCS7u0l8"
      },
      "source": [
        "### Chi Square distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ZuVjpzsOCIfU",
        "outputId": "d9b6974b-fbe1-411f-d23d-61c04ed5397b"
      },
      "source": [
        "#initialize the seed to 25\r\n",
        "np.random.seed(25)\r\n",
        "\r\n",
        "#degree of freedom 2 and size (2, 3)\r\n",
        "np.random.chisquare(df=2, size=(2, 3))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[4.08235236, 1.74587315, 0.65378557],\n",
              "       [0.41137173, 1.05899821, 0.24971095]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    }
  ]
}